package com.atguigu.dao.impl;

import com.atguigu.dao.OrderItemDao;
import com.atguigu.pojo.OrderItem;

import java.util.List;

public class OrderItemDaoImpl extends BaseDao implements OrderItemDao {
    /**
     * 保存订单向里面的
     *
     * @param orderItem
     * @return
     */
    @Override
    public int saveOrderItem(OrderItem orderItem) {
        String sql = "insert into t_order_item(name,count,price,total_price,order_id) values(?,?,?,?,?)";
        return update(sql, orderItem.getName(), orderItem.getCount(), orderItem.getPrice(), orderItem.getTotalPrice(), orderItem.getOrderId());

    }

    /**
     * 根据订单号查看订单项
     * @param orderId
     * @return
     */
    @Override
    public List<OrderItem> queryOrderItemsByOrderId(String orderId) {
        String sql="SELECT id,name,count,price,total_price totalPrice,order_id orderId FROM t_order_item WHERE order_id=?";
        return queryForList(OrderItem.class,sql,orderId);
    }

}
